<template>
  <div class="file-item" @click="$emit('file-click', file)">
    <div class="file-name">
      <component :is="getFileIcon(file.type)" :size="18" />
      <span class="file-name-text">{{ file.name }}</span>
    </div>
    <div class="file-type">{{ getFileTypeText(file.type) }}</div>
    <div class="file-size">{{ formatFileSize(file.size) }}</div>
    <div class="file-time">{{ formatMessageTime(file.date) }}</div>
    <div class="file-actions">
      <button class="action-btn" @click.stop="$emit('download', file)">
        <Download :size="16" />
      </button>
      <button class="action-btn" @click.stop="$emit('delete', file)">
        <Trash2 :size="16" />
      </button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Download, Trash2 } from 'lucide-vue-next'
import { getFileIcon, getFileTypeText, formatFileSize } from '@/utils/fileUtils'
import { formatMessageTime } from '@/utils/dateUtils'

const props = defineProps({
  file: {
    type: Object,
    required: true
  }
})

defineEmits(['file-click', 'download', 'delete'])
</script>

<style scoped>
.file-item {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 100px;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--theme-border-light);
  align-items: center;
  transition: background-color 0.2s ease;
  cursor: pointer;
  height: 56px;
}

.file-item:hover {
  background-color: var(--theme-bg-tertiary);
}

.file-item:last-child {
  border-bottom: none;
}

.file-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--theme-text-primary);
  font-weight: 500;
}

.file-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-type,
.file-size,
.file-time {
  color: var(--theme-text-secondary);
  font-size: 14px;
}

.file-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background-color: transparent;
  color: var(--theme-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background-color: var(--theme-bg-primary);
  color: var(--theme-primary);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .file-item {
    grid-template-columns: 3fr 1fr 1fr 100px;
    gap: 12px;
  }

  .file-type {
    display: none;
  }
}

@media (max-width: 480px) {
  .file-item {
    grid-template-columns: 2fr 1fr 80px;
    gap: 8px;
    font-size: 13px;
  }

  .file-type,
  .file-time {
    display: none;
  }

  .file-name,
  .file-size {
    font-size: 13px;
  }
}
</style>
